package com.ty.day4;

import java.util.*;
import java.util.function.Consumer;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @ create : 2023/11/27 9:44
 */
public class One {
    public static void main11(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("ty01");
        list.add("ty02");
        list.add("ty03");
        list.add("ty04");
        //遍历，迭代器
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        System.out.println("********");
        //forEach
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("********");
        //forEach---lambda表达式
        list.forEach((s)->{
            System.out.println(s);
        });
        System.out.println("*******");
        list.forEach(System.out::println);
        System.out.println("********");
        for (String s : list) {
            System.out.println(s);
        }
    }

}
 class Bclass{
     static int[] a = {1,3,4,5,7,8,9,10,13,35,40,50};
    public static void main(String args[]) {
        Long s=1L;
        for (int i = 1;i<=9;i++){
            s*=i;
        }
        System.out.println(s);
        System.out.println(Arrays.toString(a));
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入查找的数：");
        int x=sc.nextInt();
        int start = 0,end=a.length-1,mid=(start+end)/2,flag=0;
        if(x<a[start]||x>a[end]){
            flag=-1;
        }
        while (start<=end&&flag!=-1){

            if (a[mid]==x){
                flag=1;
                break;
            }else if (a[mid]<x){
                start=mid+1;
            }else {
                end=mid-1;
            }
            mid=(start+end)/2;
            if (start>end){
                break;
            }
        }
        if (flag!=-1){
            System.out.println("在第"+(mid+1)+"个位置");
        }else {
            System.out.println("没找到");
        }
        int result=find(0,a.length-1,a.length/2,x);
        if (result!=-1){
            System.out.println("在第"+(result+1)+"个位置");
        }else {
            System.out.println("没找到");
        }


    }
    static int find(int start,int end,int index,int x){
        if(start>end){
            return -1;
        }
        if (a[index]==x){
            return index;
        }else if (a[index]<x){
            return find(index+1,end,(end+index+1)/2,x);
        }else {
            return find(0,index-1,(index-1)/2,x);
        }
    }
}